import { TweenLite } from "../TweenLite";
import { PropTween } from "../core/PropTween";
type int = number;
//class TweenPlugin
    
    export  class TweenPlugin
    {
        constructor()
        {
            
            this._tweens = [];
            return;
        }

        public onInitTween(arg1: Object, arg2, arg3: TweenLite): Boolean
        {
            this.addTween(arg1, this.propName, arg1[this.propName], arg2, this.propName);
            return true;
        }

        protected addTween(arg1: Object, arg2: string, arg3: number, arg4, arg5: string=null): void
        {
            var loc1=NaN;
            if (arg4 != null) 
            {
                if ((loc1 = typeof arg4 != "number" ? Number(arg4) : number(arg4) - arg3) != 0) 
                {
                    this._tweens[this._tweens.length] = new PropTween(arg1, arg2, arg3, loc1, arg5 || arg2, false);
                }
            }
            return;
        }

        protected updateTweens(arg1: number): void
        {
            var loc2=null;
            var loc3=NaN;
            var loc1=this._tweens.length;
            if (this.round) 
            {
                while (loc1--) 
                {
                    loc2 = this._tweens[loc1];
                    loc3 = loc2.start + loc2.change * arg1;
                    loc2.target[loc2.property] = loc3 > 0 ? int(loc3 + 0.5) : int(loc3 - 0.5);
                }
            }
            else 
            {
                while (loc1--) 
                {
                    loc2 = this._tweens[loc1];
                    loc2.target[loc2.property] = loc2.start + loc2.change * arg1;
                }
            }
            return;
        }

        public set changeFactor(arg1: number)
        {
            this.updateTweens(arg1);
            this._changeFactor = arg1;
            return;
        }

        public get changeFactor(): number
        {
            return this._changeFactor;
        }

        public killProps(arg1: Object): void
        {
            var loc1=this.overwriteProps.length;
            while (loc1--) 
            {
                if (!(this.overwriteProps[loc1] in arg1)) 
                {
                    continue;
                }
                this.overwriteProps.splice(loc1, 1);
            }
            loc1 = this._tweens.length;
            while (loc1--) 
            {
                if (!(PropTween(this._tweens[loc1]).name in arg1)) 
                {
                    continue;
                }
                this._tweens.splice(loc1, 1);
            }
            return;
        }

        /* internal  */static onTweenEvent(arg1: string, arg2: TweenLite): Boolean
        {
            var loc2=false;
            var loc3=null;
            var loc4=0;
            var loc1=arg2.cachedPT1;
            if (arg1 != "onInit") 
            {
                while (loc1) 
                {
                    if (loc1.isPlugin && loc1.target[arg1]) 
                    {
                        if (loc1.target.activeDisable) 
                        {
                            loc2 = true;
                        }
                        var loc5;
                        (loc5 = loc1.target)[arg1]();
                    }
                    loc1 = loc1.nextNode;
                }
            }
            else 
            {
                loc3 = [];
                while (loc1) 
                {
                    loc3[loc3.length] = loc1;
                    loc1 = loc1.nextNode;
                }
                loc3.sortOn("priority", Array.NUMERIC | Array.DESCENDING);
                loc4 = loc3.length;
                while (loc4--) 
                {
                    PropTween(loc3[loc4]).nextNode = loc3[loc4 + 1];
                    PropTween(loc3[loc4]).prevNode = loc3[(loc4 - 1)];
                }
                arg2.cachedPT1 = loc3[0];
            }
            return loc2;
        }

        public static activate(arg1: Array<any>): Boolean
        {
            var loc2=null;
            TweenLite.onPluginEvent = TweenPlugin.onTweenEvent;
            var loc1=arg1.length;
            while (loc1--) 
            {
                if (!arg1[loc1].hasOwnProperty("TweenPlugin.API")) 
                {
                    continue;
                }
                loc2 = new (arg1[loc1] as Class)();
                TweenLite.plugins[loc2.propName] = arg1[loc1];
            }
            return true;
        }

        public static /* const */VERSION: number=1.31;

        public static /* const */API: number=1;

        public /* var */propName: string;

        public /* var */overwriteProps: Array<any>;

        public /* var */round: Boolean;

        public /* var */priority: int=0;

        public /* var */activeDisable: Boolean;

        public /* var */onComplete: Function;

        public /* var */onEnable: Function;

        public /* var */onDisable: Function;

        protected /* var */_tweens: Array<any>;

        protected /* var */_changeFactor: number=0;
    }
